package com.cndw.kungfu.controller;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.cndw.kungfu.comm.PositionInspection;
import com.cndw.kungfu.comm.tencent.LogFieldType;
import com.cndw.kungfu.comm.tencent.QQDC;
import com.cndw.kungfu.config.Constants;
import com.cndw.kungfu.config.ConstantsChat;
import com.cndw.kungfu.config.ConstantsConfig;
import com.cndw.kungfu.config.ConstantsCost;
import com.cndw.kungfu.config.ConstantsDailyItem;
import com.cndw.kungfu.config.ConstantsDayIntKey;
import com.cndw.kungfu.config.ConstantsIntKey;
import com.cndw.kungfu.config.ConstantsLog;
import com.cndw.kungfu.config.ConstantsModel;
import com.cndw.kungfu.config.ConstantsTask;
import com.cndw.kungfu.config.GoodsEffectConfig;
import com.cndw.kungfu.domain.GoodsMode;
import com.cndw.kungfu.domain.Npc;
import com.cndw.kungfu.domain.Player;
import com.cndw.kungfu.domain.Scene;
import com.cndw.kungfu.domain.Script;
import com.cndw.kungfu.domain.Story;
import com.cndw.kungfu.domain.Task;
import com.cndw.kungfu.domain.TaskMode;
import com.cndw.kungfu.domain.UnionAsset;
import com.cndw.kungfu.ext.LangUtil;
import com.cndw.kungfu.ext.LanguageLib;
import com.cndw.kungfu.ext.NumberProcesser;
import com.cndw.kungfu.ext.StringProcesser;
import com.cndw.kungfu.ext.TimeProcesser;
import com.cndw.kungfu.model.Context;
import com.cndw.kungfu.model.battle.Battle;
import com.cndw.kungfu.model.goods.PlayerBoxs;
import com.cndw.kungfu.model.goods.domain.SubPops;
import com.cndw.kungfu.model.sys.ChatMain;
import com.cndw.kungfu.model.sys.LogServer;
import com.cndw.kungfu.model.task.DartTask;
import com.cndw.kungfu.model.task.PlayerTasks;
import com.cndw.kungfu.model.task.TaskCondition;
import com.cndw.kungfu.model.task.TaskManager;
import com.cndw.kungfu.vo.DartTaskVO;
import com.cndw.kungfu.vo.PlayerChangeVO;
import com.cndw.kungfu.vo.PlayerReceiveVO;
import com.cndw.kungfu.vo.TaskVO;
import com.cndw.rpg.annotation.Controller;
import com.cndw.rpg.framework.ResponseMessage;
import com.cndw.rpg.framework.Session;

/**
 * 任务处理 性能问题有待调整
 * 
 * @author fantadust
 * 
 */
@Controller
public class TaskController {
	@Autowired
	private TaskManager taskManager;

	/**
	 * 接受任务
	 * 
	 * @param session
	 * @param taskId
	 */
	public ResponseMessage accept(Session session, int taskId, int npcId) {
		long playerId = session.getUid();
		PlayerTasks playerTasks = Context.getTaskServer().getPlayerTasks(playerId);
		Player player = Context.getPlayerServer().getByPlayerId(playerId);

		if (playerTasks.currentCanDo(taskId) || player.getDataInfo().getCycleTaskMap().values().contains(taskId)) {

		} else {
			return null;// 不可接任务
		}
		if (playerTasks.isDoing(taskId)) {
			return null;// 正在做
		} else if (playerTasks.geTasks().size() > ConstantsConfig.getTaskAcceptMax()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("task.accept.errmax"));
		}

		TaskMode taskMode = taskManager.getModeById(taskId);
		if (taskMode.getSourceNpcId() != npcId) {
			return null;
		} else if (taskMode.isTypeIntent() || taskMode.isTypeSecret()) {
			return null;
		}
		if (!PositionInspection.checkNpc(player, npcId)) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.position.err"));
		}

		if (taskMode.isTypeDart()) {
			if (player.stateContains(Constants.playerState256_dart)) {
				return ResponseMessage.ticpErrMsg(LanguageLib.get("task.accept.rundart"));
			} else if (player.getTeam() != null) {
				return ResponseMessage.ticpErrMsg(LanguageLib.get("task.accept.dartteam"));
			}
			for (Task e : playerTasks.geTasks()) {
				TaskMode e2 = taskManager.getModeById(e.getTaskId());
				if (e2 != null && e2.isTypeDart()) {
					return ResponseMessage.ticpErrMsg(LanguageLib.get("task.accept.rundart"));
				}
			}
		}

		int[] giveItem = null;
		if (taskMode.getGiveItem() != null) {
			giveItem = StringProcesser.toIntArray(taskMode.getGiveItem());
			if (giveItem != null && giveItem.length > 2) {
				GoodsMode goodsMode = Context.getGoodsServer().getModeById(giveItem[0]);
				if (goodsMode != null && !goodsMode.isTaskItem()) {
					int block = NumberProcesser.ceil(giveItem[1], goodsMode.getMaxStack());
					PlayerBoxs playerBoxs = player.getPlayerBoxs();
					if (!playerBoxs.checkBlack(block)) {
						return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.player.boxmin", block));
					}
				}
			}
		}

		Task task = taskManager.acceptTask(playerId, taskId);
		if (task == null) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.sys"));
		}

		if (giveItem != null && giveItem.length > 2) {
			Context.getGoodsServer().giveGoodsBing(playerId, giveItem[0], giveItem[1], 1);
		}

		if (taskMode.isTypeDart()) {
			player.stateAdd(Constants.playerState256_dart);
			player.getDataInfo().intDataSet(ConstantsIntKey.dartFreeR, 1);
			Context.getDataServer().dartTaskAdd(new DartTask(task, npcId));
		}

		Map<String, Object> map = new HashMap<String, Object>();

		Context.getTaskServer().autoRaidioTask(playerId, 1);

		LogServer.recordLog(player, ConstantsLog.task, 20005, taskMode.getName());

		map.put("suc", true);
		map.put("tips", LanguageLib.get("task.accept.suc"));
		QQDC.getInstance().logClick(player, LogFieldType.taskAcp);
		return ResponseMessage.getSuccMessage(map);

	}

	/**
	 * 指定接受某个任务
	 * 
	 * @param session
	 * @param npcId
	 * @param scriptId
	 * @return
	 */
	public ResponseMessage acceptCycleTask(Session session, int npcId, int scriptId) {
		Script script = Context.getCongfigServer().getScript(scriptId);
		if (script == null) {
			return null;
		}

		int type = Integer.valueOf(script.getParameters());
		long playerId = session.getUid();
		Player player = Context.getPlayerServer().getByPlayerId(playerId);
		if (!PositionInspection.checkNpc(player, npcId)) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.position.err"));
		}
		if (player.getUnionId() <= 0 && type == TaskMode.typeUnionCycle) {
			return ResponseMessage.ticpMsg(LanguageLib.get("task.accept.nounion"));
		}
		int laveTimes = Context.getTaskServer().getTaskLaveTimes(playerId, type);
		if (laveTimes <= 0) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("task.accept.cyclemax"));
		}

		int taskId = 0;
		if (player.getDataInfo().getCycleTaskMap().containsKey(npcId)) {
			taskId = player.getDataInfo().getCycleTaskMap().get(npcId);
			if (taskManager.getModeById(taskId) == null) {
				taskId = 0;
			}
		}
		if (taskId == 0) {
			PlayerTasks playerTasks = Context.getTaskServer().getPlayerTasks(playerId);
			List<Integer> ids = playerTasks.getSpecialIds(npcId);
			if (ids == null) {
				return ResponseMessage.ticpErrMsg(LanguageLib.get("task.cycle.notask"));
			}
			int signId = NumberProcesser.mtRand(ids.size());
			taskId = ids.get(signId - 1);
			TaskMode taskMode = taskManager.getModeById(taskId);
			if (taskMode.getType() != type) {
				return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.sys"));
			}

			player.getDataInfo().getCycleTaskMap().put(npcId, taskId);
			player.getDataInfo().commitSync();
		}

		List<TaskVO> taskVOs = Context.getTaskServer().toTaskVO(playerId, false, taskId);
		TaskVO taskVO = taskVOs.get(0);

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("task", taskVO);
		map.put("laveTimes", laveTimes);
		map.put("overTimes", player.getDataInfo().getEveryDay().getTaskTimes(type));

		map.put("taskRefreshGold", ConstantsModel.taskRefreshGold);
		map.put("taskRefreshAsset", ConstantsModel.taskRefreshAsset);
		map.put("coefficient", Context.getTaskServer().checkPrestigeDouble(TimeProcesser.getUnixTime(), 0));
		map.put("gold", player.getGold());
		map.put("goldBing", player.getGoldBing());
		return ResponseMessage.getSuccMessage(map);
	}

	/**
	 * 刷新轮回任务 返回数据 同 acceptCycleTask
	 * 
	 * @param session
	 * @param npcId
	 * @param scriptId
	 * @param payType
	 * @return
	 */
	public ResponseMessage refreshCycleTask(Session session, int npcId, int scriptId, int payType) {
		long playerId = session.getUid();
		Player player = Context.getPlayerServer().getByPlayerId(playerId);
		// 没有任务不给刷新
		if (player.getDataInfo().getCycleTaskMap().containsKey(npcId) == false) {
			return null;
		}
		if (!PositionInspection.checkNpc(player, npcId)) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.position.err"));
		}
		int taskId = player.getDataInfo().getCycleTaskMap().get(npcId);
		PlayerTasks playerTasks = Context.getTaskServer().getPlayerTasks(playerId);
		if (playerTasks.isDoing(taskId)) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("task.refresh.isdoing"));
		}

		if (payType == 0) {
			if (player.getAsset() < ConstantsModel.taskRefreshAsset) {
				return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.asset"));
			}
			player.alterAsset(-ConstantsModel.taskRefreshAsset);
			Context.getPlayerServer().change(PlayerChangeVO.PLAYER_ASSET, player.getAsset(), playerId);

		} else if (payType == 1) {
			if (player.getGoldAll() < ConstantsModel.taskRefreshGold) {
				return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.gold"));
			}
			player.alterGoldAll(-ConstantsModel.taskRefreshGold);
			Context.getPlayerServer().change(PlayerChangeVO.PLAYER_GOLD, player.getGold(), playerId);

			LogServer.costEventLog(playerId, ConstantsModel.taskRefreshGold, ConstantsCost.taskRefresh);
		} else {
			return null;
		}

		TaskMode taskMode = taskManager.getModeById(taskId);

		// 添加“任务-刷新任务”日志
		LogServer.recordLog(player, ConstantsLog.task, 20002, payType == 0 ? ConstantsModel.taskRefreshAsset : 0, payType == 0 ? 0
				: ConstantsModel.taskRefreshGold, taskMode.getType());

		player.getDataInfo().getCycleTaskMap().remove(npcId);

		player.commitSync();// 提交同步
		return acceptCycleTask(session, npcId, scriptId);
	}

	public ResponseMessage refreshCycleTastFast(Session session, int npcId, int scriptId, int payType) {
		if (payType < 0 | payType > 1) {
			return null;
		}
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		// 没有任务不给刷新
		if (player.getDataInfo().getCycleTaskMap().containsKey(npcId) == false) {
			return null;
		}
		if (!PositionInspection.checkNpc(player, npcId)) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.position.err"));
		}
		int taskId = player.getDataInfo().getCycleTaskMap().get(npcId);
		PlayerTasks playerTasks = Context.getTaskServer().getPlayerTasks(session.getUid());
		if (playerTasks.isDoing(taskId)) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("task.refresh.isdoing"));
		}
		List<Integer> ids = playerTasks.getSpecialIds(npcId);
		if (ids == null || ids.size() == 1) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("task.cycle.notask"));
		}
		TaskMode taskMode = null;
		boolean isOk = false;
		for (Integer tid : ids) {
			taskMode = taskManager.getModeById(tid);
			if (taskMode.getColor() >= 4) {
				isOk = true;
				break;
			}

		}
		if (!isOk) {
			return null;
		}
		int refreshTimes = 0;
		do {
			if (payType == 0) {
				if (player.getAsset() < ConstantsModel.taskRefreshAsset * (refreshTimes + 1)) {
					break;
				}
			} else {
				if (player.getGoldAll() < ConstantsModel.taskRefreshGold * (refreshTimes + 1)) {
					break;
				}
			}
			refreshTimes++;
			int signId = NumberProcesser.mtRand(ids.size());
			taskId = ids.get(signId - 1);
			taskMode = taskManager.getModeById(taskId);

		} while (taskMode.getColor() < 4);
		player.getDataInfo().getCycleTaskMap().put(npcId, taskId);
		player.getDataInfo().commitSync();
		boolean suc = taskMode.getColor() >= 4;
		int costAsset = 0, costGold = 0;
		if (payType == 0) {
			costAsset = ConstantsModel.taskRefreshAsset * refreshTimes;
			player.alterAsset(-costAsset);
		} else {
			costGold = ConstantsModel.taskRefreshGold * refreshTimes;
			if (costGold <=0) {
				return null;
			}
			player.alterGoldAll(-costGold);
			LogServer.costEventLog(session.getUid(), costGold, ConstantsCost.taskRefresh);
		}
		// 添加“任务-刷新任务”日志
		LogServer.recordLog(player, ConstantsLog.task, 20002, costAsset, costGold, taskMode.getType(), taskMode.getColor(), taskId);

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("refreshTimes", refreshTimes);
		map.put("suc", suc);
		map.put("asset", player.getAsset());
		map.put("gold", player.getGold());
		map.put("goldBing", player.getGoldBing());
		map.put("costAsset", costAsset);
		map.put("costGold", costGold);
		return ResponseMessage.getSuccMessage(map);
	}

	/**
	 * 放弃任务
	 * 
	 * @param session
	 * @param taskId
	 */
	public ResponseMessage cancel(Session session, int taskId) {
		long playerId = session.getUid();

		PlayerTasks playerTasks = Context.getTaskServer().getPlayerTasks(playerId);
		if (playerTasks.isDoing(taskId) == false) {
			return null;
		}
		Task task = playerTasks.geTask(taskId);
		if (task.getStatus() != Task.STATUS_DOING) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("task.cance.finish"));
		}
		TaskMode taskMode = taskManager.getModeById(taskId);
		if (taskMode.isTypeMain() || taskMode.isTypeDream()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("task.cancel.ismain"));
		}
		Player player = Context.getPlayerServer().getByPlayerId(playerId);
		// player.getDataInfo().getEveryDay().setTaskCacnel(taskMode.getType());

		if (taskMode.isTypeDart()) {
			if (player.getDataInfo().intDataGet(ConstantsIntKey.dartFreeR) != 1) {
				return ResponseMessage.ticpErrMsg(LanguageLib.get("task.cancel.dart"));
			}
			DartTask dartTask = Context.getDataServer().dartTaskGet(playerId);
			if (dartTask != null && dartTask.getTargets() != null) {
				return ResponseMessage.ticpErrMsg(LanguageLib.get("task.cancel.dartkill"));
			}
		}

		// player.getDataInfo().getCycleTaskMap().remove(taskMode.getSourceNpcId());
		player.getDataInfo().commitSync();
		taskManager.cancelTask(playerId, taskId);
		playerTasks.cancelTask(task);
		Context.getTaskServer().autoRaidioTask(playerId, 1);

		if (taskMode.isTypeDart()) {
			player.stateRemove(Constants.playerState256_dart);
			player.getDataInfo().intDataRemove(ConstantsIntKey.dartFreeR);
			Context.getDataServer().dartTaskRemove(playerId);
		}
		LogServer.recordLog(player, ConstantsLog.task, 20006, taskMode.getName());

		return ResponseMessage.getSuccMessage(true);
	}

	/**
	 * 提交任务
	 * 
	 * @param session
	 * @param taskId
	 */
	public ResponseMessage submit(Session session, int taskId, int npcId, int goodsId) {
		long playerId = session.getUid();
		PlayerTasks playerTasks = taskManager.getPlayerTasksById(playerId);
		Player player = Context.getPlayerServer().getByPlayerId(playerId);
		if (!playerTasks.isDoing(taskId)) {
			return null;
		} else if (!playerTasks.currentCanDo(taskId)) {
			return null;
		}
		if (!PositionInspection.checkNpcMain(player, npcId)) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.position.err"));
		}
		TaskMode taskMode = taskManager.getModeById(taskId);
		Task task = playerTasks.geTask(taskId);
		if (taskMode.getTargetNpcId() != npcId) {
			return null;
		}
		if (task.getStatus() != Task.STATUS_FINISH && taskManager.checkOneTask(playerId, task) == false) {
			return null;
		}

		PlayerBoxs playerBoxs = player.getPlayerBoxs();
		int goodsNum = 0;
		goodsNum += taskMode.getTaskAwards() == null ? 0 : taskMode.getTaskAwards().size();
		goodsNum += goodsId > 0 ? 1 : 0;
		if (!playerBoxs.checkBlack(goodsNum)) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.player.boxmin", goodsNum));
		}

		List<TaskCondition> conditions = taskMode.getTaskConditionsList();
		StringBuffer logSb = new StringBuffer();
		if (conditions != null) {// 删除任务品
			for (TaskCondition e : conditions) {
				if (e.isCollectGoods()) {
					playerBoxs.costGoods(e.getTargerId(), e.getCount());
					GoodsMode goodsMode = Context.getGoodsServer().getModeById(e.getTargerId());
					if (goodsMode != null) {
						logSb.append("|" + goodsMode.getName() + ":" + e.getCount());
					}
				}
			}
		}

		task.setStatus(Task.STATUS_END);
		task.setFinishTime(TimeProcesser.getUnixTime());
		taskManager.updateStatus(task);
		playerTasks.submitTask(task);

		if (taskMode.getGiveItem() != null) {
			try {
				int[] items = StringProcesser.toIntArray(taskMode.getGiveItem());
				if (items != null && items.length >= 3 && items[2] == 1) {
					playerBoxs.costGoods(items[0], items[1]);
					GoodsMode goodsMode = Context.getGoodsServer().getModeById(items[0]);
					if (goodsMode != null) {
						logSb.append("|" + goodsMode.getName() + ":" + items[1]);
					}
				}

			} catch (Exception e) {
				e.printStackTrace();
			}

		}
		StringBuffer logSB = new StringBuffer();

		// 记录任务获得物品
		if (taskMode.getTaskAwards() != null) {// 给人物奖励
			Context.getGoodsServer().giveSubPops(taskMode.getTaskAwards(), player, logSB);
		}
		// 给任选其一的奖励
		if (taskMode.getChooseOneRewards() != null) {
			for (SubPops e : taskMode.getChooseOneRewards()) {
				if (e.getGoodsId() == goodsId) {
					GoodsMode goodsMode = Context.getGoodsServer().getModeById(e.getGoodsId());
					if (goodsMode != null) {
						Context.getGoodsServer().giveGoodsBing(playerId, e.getGoodsId(), e.getNum(), e.getBind());
						logSB.append("|" + goodsMode.getName() + ":" + e.getNum());

						if (taskMode.getTaskId() == 5299) {
							// ChatMain.hearsayMessage(LanguageLib.get("chat.task.buy",
							// player.getPlayerName(),
							// LangUtil.makeChat(playerId, goodsMode)),
							// ConstantsChat.cwNormal);
							ChatMain.hearsayMessage(LanguageLib.get("chat.task.buy", LangUtil.makeNameLink(player), LangUtil.makeChat(playerId, goodsMode)),
									ConstantsChat.cwNormal);
						}
					}
					break;
				}
			}
		}

		int awardsCoefficient = 1;
		if (taskMode.getType() == TaskMode.typeUnionCycle) {
			if (player.getDataInfo().getEveryDay().getTaskTimes(TaskMode.typeUnionCycle) < 15) {
				awardsCoefficient = 3;
			}
		}
		int quality = task.getQuality() == 0 ? 10 : task.getQuality();

		int exp = taskMode.getPlayerExp() * awardsCoefficient * quality / 10;
		int asset = taskMode.getPlayerAsset() * awardsCoefficient * quality / 10;
		int goldTicke = taskMode.getPlayerGoldTicke() * awardsCoefficient * quality / 10;

		if (taskMode.isTypeDart()) {
			if (TimeProcesser.inTimePeriod(11 * 3600, 12 * 3600) || TimeProcesser.inTimePeriod(20 * 3600 + 1800, 21 * 3600)) {// 双倍押镖时间
				exp = exp * 3 / 2;
				asset = asset * 3 / 2;
			}
			DartTask dart = Context.getDataServer().dartTaskGet(playerId);
			if (dart != null) {
				exp -= Math.abs(ConstantsModel.taskDartLost[dart.getFails()] / 10 * taskMode.getPlayerExp() * quality / 100);
			}
		}

		int taskPrestige = 0;
		if (taskMode.getType() == TaskMode.typePrestige) {
			Context.getTaskServer().notifyToSpark(playerId, ConstantsTask.spark18TaskPrestige, 1);
			// 加到每日奖励
			player.getDataInfo().getEveryDay().finishDailyItem(ConstantsDailyItem.finishPrestigeTaskItem);
			if (taskMode.getPrestige() > 0) {
				Npc npc = Context.getCacheCenter().getNpcById(npcId);
				taskPrestige = taskMode.getPrestige() * awardsCoefficient * quality / 10;
				player.getDataInfo().alterPrestige(npc.getSceneId(), taskPrestige);
				Context.getGeneralServer().addTilte(player.getPlayerId(), Constants.titlePrestige, 0);
			}

		}
		// 商会跑环任务增加资金声望和资源
		int unionGest = 0;
		int unionAsset = 0;
		int unionDedicate = 0;
		if (taskMode.getType() == TaskMode.typeUnionCycle) {
			Context.getTaskServer().notifyToSpark(playerId, ConstantsTask.spark17TaskUnionCycle, 1);
			// 加到每日奖励
			player.getDataInfo().getEveryDay().finishDailyItem(ConstantsDailyItem.unionTaskItem);
			unionGest = taskMode.getUnionGest() * awardsCoefficient * quality / 10;
			unionAsset = taskMode.getUnionAsset() * awardsCoefficient * quality / 10;
			unionDedicate = taskMode.getUnionDedicate() * awardsCoefficient * quality / 10;
			if (player.getUnionId() > 0) {
				Context.getUnionServer().addResource(playerId, unionGest, unionAsset, unionDedicate, UnionAsset.finishTask);
			}
		} else if (taskMode.isTypeDaily()) {
			// 加入到每日奖励
			player.getDataInfo().getEveryDay().finishDailyItem(ConstantsDailyItem.finishDailyTaskItem);
		}

		// 多个类型一起增加任务次数
		if (taskMode.isSpecialType()) {
			player.getDataInfo().getEveryDay().alterTaskTimes(taskMode.getType());
			player.getDataInfo().getCycleTaskMap().remove(taskMode.getSourceNpcId());
			player.getDataInfo().commitSync();
		}
		if (goldTicke > 0) {
			player.alterGoldTicke(goldTicke);
		}
		player.alterExp(exp);
		player.alterAsset(asset);

		PlayerReceiveVO receive = new PlayerReceiveVO();
		receive.put(PlayerReceiveVO.RECEIVE_EXP, exp);
		receive.put(PlayerReceiveVO.RECEIVE_ASSET, asset);
		if (goldTicke > 0) {
			receive.put(PlayerReceiveVO.RECEIVE_GOLDTICKE, goldTicke);
		}

		if (taskMode.isTypeMain()) {
			if (player.getDataInfo().getMainTaskId() < taskMode.getTaskId()) {
				player.getDataInfo().setMainTaskId(taskMode.getTaskId());
			}
		} else if (taskMode.isTypeDart()) {
			player.stateRemove(Constants.playerState256_dart);
			player.getDataInfo().intDataRemove(ConstantsIntKey.dartFreeR);
			Context.getTaskServer().notifyToSpark(playerId, ConstantsTask.spark19TaskDart, 1);
			// 加到每日奖励
			player.getDataInfo().getEveryDay().finishDailyItem(ConstantsDailyItem.finishDartTaskItem);
			Context.getDataServer().dartTaskRemove(playerId);
			player.getDataInfo().alterExpRet(Constants.expRet_dart);// 参加活动标记
		}

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("suc", true);

		map.put("prestige", taskPrestige);
		map.put("unionGest", unionGest);
		map.put("unionAsset", unionAsset);
		map.put("unionDedicate", unionDedicate);

		if (taskMode.isTypeDart()) {
			map.put("laveTimes", Context.getTaskServer().getTaskLaveTimes(playerId, taskMode.getType()));
		} else if (taskMode.isTypeMain()) {
			Context.getTaskServer().checkAwaitSecret(player.getPlayerId());// 检测秘典任务
		}

		Context.getTaskServer().autoRaidioTask(playerId, 1);

		map.put(PlayerReceiveVO.RADIO_NAME, receive);
		player.commitSync();// 提交同步

		LogServer.recordLog(player, ConstantsLog.task, 20001, taskMode.getName(), taskId, logSb.toString(), exp, taskPrestige, asset, goldTicke,
				logSB.toString(), quality, awardsCoefficient, unionGest, unionAsset, unionDedicate);
		QQDC.getInstance().logClick(player, LogFieldType.taskSub);
		return ResponseMessage.getSuccMessage(map);

	}

	/**
	 * 更新品质
	 * 
	 * @param session
	 * @param taskId
	 * @return
	 */
	public ResponseMessage updateQuality(Session session, int taskId, int goodsId) {

		if (NumberProcesser.contains(GoodsEffectConfig.taskQualityIds, goodsId) == false) {
			return null;
		}
		GoodsMode goodsMode = Context.getGoodsServer().getModeById(goodsId);
		if (goodsMode == null) {
			return null;
		}
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		PlayerBoxs playerBoxs = player.getPlayerBoxs();
		if (!playerBoxs.isHaveGoods(goodsId)) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.goods"));
		}
		PlayerTasks playerTasks = Context.getTaskServer().getPlayerTasks(session.getUid());
		Task task = playerTasks.geTask(taskId);
		if (task == null || task.getStatus() == Task.STATUS_END) {
			return null;
		}
		TaskMode taskMode = taskManager.getModeById(taskId);
		if (taskMode.isTypeDart()) {
			return null;
		}
		if (!taskMode.isSpecialType()) {
			return null;
		}

		if (task.getQuality() >= goodsMode.getValueA()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("task.quality.errlevel"));
		}
		playerBoxs.costGoods(goodsId, 1);
		task.setQuality(goodsMode.getValueA());
		taskManager.updateStatus(task);

		LogServer.recordLog(player, ConstantsLog.task, 20007, taskMode.getName(), task.getQuality(), playerBoxs.getStackNum(goodsId));

		return ResponseMessage.getSuccMessage(task.getQuality());
	}

	public ResponseMessage dartRefresh(Session session, int taskId, int type) {
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		PlayerTasks playerTasks = Context.getTaskServer().getPlayerTasks(session.getUid());
		Task task = playerTasks.geTask(taskId);
		if (task == null || task.getStatus() == Task.STATUS_END) {
			return null;
		}
		TaskMode taskMode = taskManager.getModeById(taskId);
		if (!taskMode.isTypeDart()) {
			return null;
		}
		if (task.getQuality() == 50) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("task.refresh.ismax"));
		}

		int constGold = 0;
		boolean costGoods = false;
		int haveTool = player.getPlayerBoxs().getStackNum(GoodsEffectConfig.dartId);
		boolean isMax = false;
		if (type == 0) {// 免费
			if (player.getDataInfo().intDataGet(ConstantsIntKey.dartFreeR) != 1) {
				return ResponseMessage.ticpErrMsg(LanguageLib.get("task.refresh.nofree"));
			}
			player.getDataInfo().intDataRemove(ConstantsIntKey.dartFreeR);

		} else if (type == 1) {// 正常刷新
			costGoods = haveTool > 0;
			constGold = costGoods ? 0 : 10;
		} else {
			if (player.getKnight() == null || !player.getKnight().isOpenDartMaxFast()) {
				return ResponseMessage.ticpErrMsg(LanguageLib.get("task.refresh.nomax"));
			}
			constGold = 50;
			isMax = true;
		}

		if (player.getGoldAll() < constGold) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.gold"));
		}
		if (constGold > 0) {
			player.alterGoldAll(-constGold);
			player.commitSync();
			LogServer.costEventLog(session.getUid(), constGold, ConstantsCost.taskDartRefresh);
		}
		if (type == 1) {
			player.getDataInfo().getEveryDay().intDataAlter(ConstantsDayIntKey.dartRTimes, 1);
			if (player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.dartRTimes) >= 10) {
				isMax = true;
				player.getDataInfo().getEveryDay().intDataRemove(ConstantsDayIntKey.dartRTimes);
			}
		}
		if (costGoods) {
			player.getPlayerBoxs().costGoods(GoodsEffectConfig.dartId, 1);
			haveTool--;
		}
		int[] qualityRate = ConstantsModel.taskDartRate;
		if (player.getKnightTrueLevel() == 2) {
			qualityRate = ConstantsModel.taskDartRate2;
		} else if (player.getKnightTrueLevel() >= 3) {
			qualityRate = ConstantsModel.taskDartRate3;
		} else if (type == 0) {// 免费使用降低几率
			qualityRate = ConstantsModel.taskDartRateFree;
		}

		int indexId = NumberProcesser.rateIndex(qualityRate);
		if (isMax) {
			indexId = 3;
		}
		int quality = ConstantsModel.taskDartQualityArr[indexId];
		task.setQuality(quality);
		taskManager.updateStatus(task);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("gold", player.getGold());
		map.put("goldBing", player.getGoldBing());
		map.put("quality", task.getQuality());
		map.put("type", type);

		if (indexId >= 1) {
			Npc npc = Context.getSceneServer().getNpcById(taskMode.getTargetNpcId());
			String message = LanguageLib.get("chat.task.dart", LangUtil.makeNameLink(player), quality / 10, LangUtil.numFormat(4 - indexId),
					LangUtil.getColor(indexId), npc.getName());
			ChatMain.hearsayMessage(message, ConstantsChat.cwDart);
		}

		LogServer.recordLog(player, ConstantsLog.task, 20011, constGold, quality, costGoods, haveTool);

		return ResponseMessage.getSuccMessage(map);
	}

	/**
	 * 快速完成任务
	 * 
	 * @param session
	 * @param taskId
	 * @return
	 */
	public ResponseMessage fastComplete(Session session, int taskId) {
		long playerId = session.getUid();
		Player player = Context.getPlayerServer().getByPlayerId(playerId);

		PlayerTasks playerTasks = Context.getTaskServer().getPlayerTasks(playerId);
		if (playerTasks.isDoing(taskId) == false) {
			return null;
		}
		Scene currentScene = Context.getSceneServer().getSceneById(player.getSceneId());
		if (currentScene.getType() == Constants.CITY_WALL || currentScene.getType() == Constants.CITY_UNDER) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("task.fast.undercity"));
		}

		Task task = playerTasks.geTask(taskId);
		if (task.getStatus() != Task.STATUS_DOING) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("task.fast.errdoing"));
		}
		TaskMode taskMode = taskManager.getModeById(taskId);
		if (taskMode.getFastPay() <= 0) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("task.fast.errtask"));
		}
		// if (taskMode.isTypeDaily() && !player.getVip().isOpenFastDaily()) {
		// return null;
		// } else if (taskMode.isTypeDart() &&
		// !player.getVip().isOpenFastDart()) {
		// return null;
		// } else if (taskMode.isSpecialType() &&
		// !player.getVip().isOpenFastUnionAndPrestige()) {
		// return null;
		// }

		if (player.getGoldAll() < taskMode.getFastPay()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.gold"));
		}

		Map<String, Object> map = new HashMap<String, Object>();

		Npc npc = Context.getSceneServer().getNpcById(taskMode.getTargetNpcId());
		if (npc.getSceneId() != player.getSceneId()) {
			player.setTx(npc.getX());// 临时更新tx,ty
			player.setTy(npc.getY());
			player.setTs(npc.getSceneId());
		} else {
			player.setX(npc.getX());
			player.setY(npc.getY());
		}

		if (taskMode.isTypeDart()) {
			player.stateRemove(Constants.playerState256_dart);
		}
		map.put("dartSceneId", npc.getSceneId());
		map.put("dartX", npc.getX());
		map.put("dartY", npc.getY());

		player.alterGoldAll(-taskMode.getFastPay());
		playerTasks.changeIds.add(taskId);
		task.setStatus(Task.STATUS_FINISH);
		taskManager.updateStatus(task);

		Context.getTaskServer().autoRaidioTask(playerId, 1);

		map.put("gold", player.getGold());
		map.put("goldBing", player.getGoldBing());
		map.put("constGold", taskMode.getFastPay());

		LogServer.recordLog(player, ConstantsLog.task, 20008, taskMode.getName(), taskMode.getFastPay());
		LogServer.costEventLog(playerId, taskMode.getFastPay(), ConstantsCost.taskFast);

		return ResponseMessage.getSuccMessage(map);
	}

	/**
	 * 登录场景抓取场景的任务
	 * 
	 * @param session
	 * @param sceneId
	 * @return
	 */
	public ResponseMessage getTasks(Session session) {

		List<TaskVO> taskVos = taskManager.getNpcsTasksVO(session.getUid());
		return ResponseMessage.getSuccMessage(taskVos);

	}

	/**
	 * 显示目标任务
	 * 
	 * @param session
	 * @param stage
	 * @return
	 */
	public ResponseMessage showIntentTasks(Session session, int stage) {
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		Integer[] taskIds = new Integer[10];
		for (int i = 0; i < 10; i++) {
			taskIds[i] = 5000 + stage * 10 + i;
		}
		List<TaskVO> taskVOs = Context.getTaskServer().toTaskVO(session.getUid(), true, taskIds);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("tasklist", taskVOs);
		map.put("intentPassStage", player.getDataInfo().intDataGet(ConstantsIntKey.intentStage));

		return ResponseMessage.getSuccMessage(map);
	}

	/**
	 * 完成目标任务
	 * 
	 * @param session
	 * @param intentId
	 * @return
	 */
	public ResponseMessage receiveIntentAward(Session session, int intentId) {
		long playerId = session.getUid();
		TaskMode taskMode = taskManager.getModeById(intentId);
		Player player = Context.getPlayerServer().getByPlayerId(playerId);
		if (taskMode == null) {
			return null;
		}
		PlayerTasks playerTasks = Context.getTaskServer().getPlayerTasks(playerId);
		if (!playerTasks.currentCanDo(intentId)) {
			return null;
		}
		Task task = playerTasks.geTask(intentId);
		if (task != null) {
			return null;
		}

		boolean isReached = taskManager.checkIsReached(playerId, taskMode);
		if (!isReached) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("task.intent.errsuc"));
		}

		int goodsNum = 0;
		goodsNum += taskMode.getTaskAwards() == null ? 0 : taskMode.getTaskAwards().size();
		if (!player.getPlayerBoxs().checkBlack(goodsNum)) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.player.boxmin", goodsNum));
		}

		task = new Task();
		task.setPlayerId(playerId);
		task.setTaskId(intentId);
		task.setStatus(Task.STATUS_END);
		task.setAddTime(TimeProcesser.getUnixTime());
		task.setFinishTime(TimeProcesser.getUnixTime());

		taskManager.acceptFinishTask(task);
		playerTasks.submitTask(task);

		player.alterExp(taskMode.getPlayerExp());
		player.alterAsset(taskMode.getPlayerAsset());
		player.alterGoldTicke(taskMode.getPlayerGoldTicke());

		StringBuffer logSb = new StringBuffer();
		// 记录任务获得物品
		if (taskMode.getTaskAwards() != null) {// 给人物奖励
			Context.getGoodsServer().giveSubPops(taskMode.getTaskAwards(), player, logSb);
		}

		PlayerReceiveVO receive = new PlayerReceiveVO();
		receive.put(PlayerReceiveVO.RECEIVE_EXP, taskMode.getPlayerExp());
		receive.put(PlayerReceiveVO.RECEIVE_ASSET, taskMode.getPlayerAsset());
		receive.put(PlayerReceiveVO.RECEIVE_GOLDTICKE, taskMode.getPlayerGoldTicke());

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("suc", true);
		map.put(PlayerReceiveVO.RADIO_NAME, receive);

		int stage = (intentId - 5000) / 10;
		boolean overStage = true;
		for (int i = 0; i < 10; i++) {
			int tempId = 5000 + stage * 10 + i;
			TaskMode tempMode = taskManager.getModeById(tempId);
			if (tempMode != null && !playerTasks.checkDoneOnce(tempId)) {
				overStage = false;
				break;
			}
		}
		if (overStage) {
			int currentValue = player.getDataInfo().intDataGet(ConstantsIntKey.intentStage);
			currentValue = currentValue | (1 << (stage + 1));
			player.getDataInfo().intDataSet(ConstantsIntKey.intentStage, currentValue);
			player.getDataInfo().commitSync();
			map.put("intentPassStage", currentValue);
		}
		LogServer.recordLog(player, ConstantsLog.task, 20009, taskMode.getName(), intentId, taskMode.getPlayerExp(), taskMode.getPlayerAsset(),
				taskMode.getPlayerGoldTicke(), logSb.toString());

		player.commitSync();

		return ResponseMessage.getSuccMessage(map);
	}

	/**
	 * 显示秘典任务
	 * 
	 * @param session
	 * @return
	 */
	public ResponseMessage secretTaskShow(Session session) {
		PlayerTasks playerTasks = Context.getTaskServer().getPlayerTasks(session.getUid());
		Collection<TaskMode> secretsList = Context.getTaskServer().getAllSecrets();
		List<Integer> taskIds = new ArrayList<Integer>();

		for (TaskMode e : secretsList) {
			taskIds.add(e.getTaskId());
			if (playerTasks.checkDoneOnce(e.getTaskId()) == false) {
				break;
			}
		}
		Integer[] ids = taskIds.toArray(new Integer[taskIds.size()]);
		List<TaskVO> taskList = Context.getTaskServer().toTaskVO(session.getUid(), false, ids);

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("taskList", taskList);

		return ResponseMessage.getSuccMessage(map);
	}

	/**
	 * 领取秘典任务奖励
	 * 
	 * @param session
	 * @param scretTaskId
	 * @return
	 */
	public ResponseMessage scretTaskAward(Session session, int scretTaskId) {
		long playerId = session.getUid();
		TaskMode taskMode = taskManager.getModeById(scretTaskId);
		Player player = Context.getPlayerServer().getByPlayerId(playerId);
		if (taskMode == null) {
			return null;
		}
		PlayerTasks playerTasks = Context.getTaskServer().getPlayerTasks(playerId);
		if (!playerTasks.currentCanDo(scretTaskId)) {
			return null;
		}
		Task task = playerTasks.geTask(scretTaskId);
		if (task != null) {
			return null;
		}

		boolean isReached = taskManager.checkIsReached(playerId, taskMode);
		if (!isReached) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("task.intent.errsuc"));
		}

		int goodsNum = 0;
		goodsNum += taskMode.getTaskAwards() == null ? 0 : taskMode.getTaskAwards().size();
		if (!player.getPlayerBoxs().checkBlack(goodsNum)) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.player.boxmin", goodsNum));
		}

		task = new Task();
		task.setPlayerId(playerId);
		task.setTaskId(scretTaskId);
		task.setStatus(Task.STATUS_END);
		task.setAddTime(TimeProcesser.getUnixTime());
		task.setFinishTime(TimeProcesser.getUnixTime());

		taskManager.acceptFinishTask(task);
		playerTasks.submitTask(task);

		player.alterExp(taskMode.getPlayerExp());
		player.alterGoldTicke(taskMode.getPlayerGoldTicke());
		player.getDataInfo().alterPrestige(2, taskMode.getPrestige());

		PlayerReceiveVO receive = new PlayerReceiveVO();
		receive.put(PlayerReceiveVO.RECEIVE_EXP, taskMode.getPlayerExp());
		receive.put(PlayerReceiveVO.RECEIVE_GOLDTICKE, taskMode.getPlayerGoldTicke());

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("suc", true);
		map.put(PlayerReceiveVO.RADIO_NAME, receive);

		LogServer.recordLog(player, ConstantsLog.task, 20010, taskMode.getName(), scretTaskId, taskMode.getPlayerExp(), taskMode.getPlayerGoldTicke(),
				taskMode.getPrestige());

		player.commitSync();
		player.getDataInfo().commitSync();

		Context.getTaskServer().autoRaidioTask(playerId, 1);

		return ResponseMessage.getSuccMessage(map);
	}

	/**
	 * 显示剧情脚本信息
	 * 
	 * @param session
	 * @param id
	 * @return
	 */
	public ResponseMessage loadStory(Session session, int id) {
		Story story = Context.getCacheCenter().getStory(id);
		if (story == null) {
			return ResponseMessage.getFailMessage(false);
		}
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		if (id < 1000 && player.getDataInfo().getLastStoryId() < id) {
			player.getDataInfo().setLastStoryId(id);
			player.commitSync();// 提交同步
		}

		return ResponseMessage.getSuccMessage(story);
	}

	/**
	 * 检查押镖任务
	 * 
	 * @param session
	 * @return
	 */
	public ResponseMessage checkDartTask(Session session, int taskId) {
		long playerId = session.getUid();
		PlayerTasks playerTasks = Context.getTaskServer().getPlayerTasks(playerId);
		if (playerTasks.isDoing(taskId) == false) {
			return ResponseMessage.getSuccMessage(false);
		}
		Task task = playerTasks.geTask(taskId);
		if (task.getStatus() != Task.STATUS_DOING) {
			return ResponseMessage.getSuccMessage(false);
		}
		TaskMode taskMode = taskManager.getModeById(taskId);
		if (!taskMode.isTypeDart()) {
			return null;
		}
		Npc npc = Context.getSceneServer().getNpcById(taskMode.getTargetNpcId());
		Player player = Context.getPlayerServer().getByPlayerId(playerId);
		if (player.getSceneId() == npc.getSceneId()) {
			task.setStatus(Task.STATUS_FINISH);
			taskManager.updateStatus(task);// 记录状态
			playerTasks.changeIds.add(taskId);
			player.stateRemove(Constants.playerState256_dart);
			Context.getTaskServer().autoRaidioTask(playerId, 1);
		}

		return ResponseMessage.getSuccMessage(true);
	}

	/**
	 * 显示押镖的列表
	 * 
	 * @param session
	 * @param npcId
	 * @return
	 */
	public ResponseMessage dartList(Session session, int npcId) {
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		Map<String, Object> map = new HashMap<String, Object>();
		List<DartTaskVO> list = new ArrayList<DartTaskVO>();
		Collection<DartTask> dartTasks = Context.getDataServer().dartTasks();
		for (DartTask e : dartTasks) {
			if (e.getTask() == null || e.getTask().getStatus() >= Task.STATUS_FINISH) {

				continue;
			} else if (e.getTargets() != null) {
				if (e.getTargets().size() >= 3 || e.getTargets().contains(session.getUid())) {
					continue;
				}
			} else if (e.getPlayerId() == session.getUid()) {
				continue;
			}

			DartTaskVO v = new DartTaskVO();

			int qua = e.getTask().getQuality() == 0 ? 10 : e.getTask().getQuality();

			Player target = Context.getPlayerServer().getByPlayerId(e.getPlayerId());
			v.setPlayerId(target.getPlayerId());
			v.setPlayerName(target.getPlayerName());
			v.setLevel(target.getLevel());
			v.setQuality(qua);
			v.setLeave(100 - ConstantsModel.taskDartLost[e.getFails()]);
			TaskMode taskMode = taskManager.getModeById(e.getTask().getTaskId());

			v.setExp(taskMode.getPlayerExp() * qua / 10 * (ConstantsModel.taskDartGot[e.getFails() + 1]) / 100);

			list.add(v);

		}
		map.put("list", list);
		map.put("leaveTimes", Context.getTaskServer().getTaskDartKillTime(player));
		map.put("taskDartKillBuy", ConstantsModel.taskDartKillBuy);
		map.put("haveBuy", player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.dartKB));

		return ResponseMessage.getSuccMessage(map);
	}

	public ResponseMessage dartKill(Session session, long targetId) {
		if (targetId == session.getUid()) {
			return null;
		}
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		if (Context.getTaskServer().getTaskDartKillTime(player) <= 0) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("task.dart.killmax"));
		} else if (player.getTeam() != null) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("team.err.controlontem"));
		}
		Player target = Context.getPlayerServer().getByPlayerId(targetId);
		if (target == null) {
			return null;
		}

		int noKill = Constants.playerState1_battle | Constants.playerState2_learn | Constants.playerState4_slaughter;

		if (player.stateContains(noKill)) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("battle.err.cooling"));
		}
		if (player.stateContains(Constants.playerState256_dart)) {// 押镖状态，不能进入副本
			return ResponseMessage.ticpErrMsg(LanguageLib.get("undercity.enter.dart"));
		}
		if (player.stateContains(Constants.playerState512_battleAuto)) {// 练功情况下不能进行
			return ResponseMessage.ticpErrMsg(LanguageLib.get("player.state.killauto"));
		}

		DartTask dartTask = Context.getDataServer().dartTaskGet(targetId);
		if (dartTask == null || dartTask.getTask().getStatus() >= Task.STATUS_FINISH) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("task.dart.nothave"));
		} else if (dartTask.getTargets() != null && dartTask.getTargets().size() >= 3) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("task.dart.notime", 3));
		} else if (dartTask.getTargets() != null && dartTask.getTargets().contains(session.getUid())) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("task.dart.ishave"));
		}

		dartTask.addTarget(session.getUid());
		// 增加我的劫镖次数
		player.getDataInfo().getEveryDay().intDataAlter(ConstantsDayIntKey.dartKill, 1);

		int[] hpMps = target.blodMagicMemory();// 对手满血满蓝

		Battle battle = new Battle(player.getLikedFighter(), target.getLikedFighter());
		battle.execBattle(Constants.battle_pvp);
		battle.broadcast(player);
		battle.clear();

		target.blodMagicMemoryRevert(hpMps);

		player.useBloodMagicBagAndPet();

		boolean isSuc = battle.getWiner() == 1;
		int exp = 0;
		int expTrue = 0;

		int qua = dartTask.getTask().getQuality() == 0 ? 10 : dartTask.getTask().getQuality();
		Scene scene = Context.getSceneServer().getSceneById(player.getSceneId());
		int indexId = qua / 10;
		indexId = indexId == 5 ? 4 : indexId;
		indexId--;
		ResponseMessage ticpMessage;
		if (isSuc) {
			TaskMode taskMode = taskManager.getModeById(dartTask.getTask().getTaskId());

			exp = taskMode.getPlayerExp() * qua / 10 * (ConstantsModel.taskDartGot[dartTask.getFails() + 1]) / 100;

			int conl = (10 - (player.getLevel() - target.getLevel()));
			conl = NumberProcesser.between(conl, 1, 10);
			expTrue = exp * conl / 10;

			player.alterExp(expTrue);
			dartTask.setFails(dartTask.getFails() + 1);
			ticpMessage = ResponseMessage.errMsg(LanguageLib.get("task.dart.killlost", player.getPlayerName(), exp));

		} else {
			ticpMessage = ResponseMessage.errMsg(LanguageLib.get("task.dart.killwin", player.getPlayerName()));
		}
		// String message =
		// LanguageLib.get(isSuc?"chat.task.dartkill":"chat.task.dartfail",
		// scene.getName(), player.getPlayerName(), target.getPlayerName(),
		// LangUtil.numFormat(4 - indexId),
		// LangUtil.getColor(indexId), expTrue);
		String message = LanguageLib.get(isSuc ? "chat.task.dartkill" : "chat.task.dartfail", scene.getName(), LangUtil.makeNameLink(player),
				LangUtil.makeNameLink(target), LangUtil.numFormat(4 - indexId), LangUtil.getColor(indexId), expTrue);
		ChatMain.hearsayMessage(message, ConstantsChat.cwDartK, battle.getCostTime() + 5);
		Context.getTcpServer().broadcastResMsg(ticpMessage, target.getPlayerId());
		LogServer.recordLog(player, ConstantsLog.task, 20012, target.getPlayerName(), isSuc, expTrue);
		LogServer.recordLog(player, ConstantsLog.task, 20014, player.getPlayerName(), isSuc, exp);

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("suc", isSuc);
		map.put("exp", expTrue);
		QQDC.getInstance().logClick(player, LogFieldType.battleDart);
		return ResponseMessage.getSuccMessage(map);
	}

	public ResponseMessage dartKillTime(Session session) {
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		int have = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.dartKB);
		if (have >= ConstantsModel.taskDartKillBuy.length) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("task.dart.buymax"));
		}
		int gold = ConstantsModel.taskDartKillBuy[have];
		if (player.getGoldAll() < gold) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.gold"));
		}
		player.alterGoldAll(-gold);
		player.getDataInfo().getEveryDay().intDataAlter(ConstantsDayIntKey.dartKB, 1);
		player.commitSync();

		LogServer.recordLog(player, ConstantsLog.task, 20013, gold, have + 1);

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("leaveTimes", Context.getTaskServer().getTaskDartKillTime(player));
		map.put("haveBuy", have + 1);
		map.put("gold", player.getGold());
		map.put("goldBing", player.getGoldBing());

		return ResponseMessage.getSuccMessage(map);
	}

}
